home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Snippets / Devices / SCSI Simple Sample / Src / (ACAM.h) next >
Encoding:
Text File  |  1994-03-24  |  28.5 KB  |  735 lines  |  [TEXT/MPS ]

  1. /*******************************************************************************
  2.  
  3.     File:        ACAM.h
  4.  
  5.     Contains:    
  6.         This file contains constants and data structures to be used by
  7.         drivers to interface with the SCSI Manager 4.3.
  8.                         
  9.     Last Modification:    12/6/93
  10.                         
  11.     Copyright:    © 1992-1993 by Apple Computer, Inc., all rights reserved.
  12.  
  13.  
  14. *******************************************************************************/
  15.  
  16. #ifndef __ACAM__
  17. #define __ACAM__    1
  18.  
  19. #include <Timer.h>
  20. #include <Types.h>
  21. #include <Traps.h>
  22. #include <OSUtils.h>
  23.  
  24. #ifndef uchar
  25. #define uchar    unsigned char
  26. #endif
  27. #ifndef ushort
  28. #define ushort    unsigned short
  29. #endif
  30. #ifndef ulong
  31. #define ulong    unsigned long
  32. #endif
  33.  
  34. #define true 1
  35. #define false 0
  36.  
  37. #define scsiVERSION 43
  38.  
  39. /********************************************************************/
  40. // Defines for the SCSIMgr function codes
  41. /********************************************************************/
  42.  
  43. enum                                         
  44. {
  45. //------------ Common Functions ------------
  46.  
  47.     SCSINop                        = 0x00,      // Execute nothing
  48.     SCSIExecIO                      = 0x01,      // Execute the specified IO
  49.     SCSIBusInquiry              = 0x03,     // Get parameters for entire path of HBAs
  50.     SCSIReleaseQ                = 0x04,        // Release the frozen SIM queue for particular LUN 
  51.     SCSISetAsyncCallback        = 0x05,        // Set async event call back 
  52.  
  53. //------------ Control Functions         ------------
  54.  
  55.     SCSIAbortCommand            = 0x10,        // Abort the selected Control Block 
  56.     SCSIResetBus                = 0x11,        // Reset the SCSI bus 
  57.     SCSIResetDevice                = 0x12,        // Reset the SCSI device 
  58.     SCSITerminateIO                = 0x13,        // Terminate any pending IO 
  59.  
  60. //------------ Target Mode Functions      ------------
  61.  
  62.     SCSIEnableLUN                = 0x30,        // Enable LUN, Target mode support
  63.     SCSITargetIO                = 0x31,        // Execute the target IO request
  64.  
  65. //------------ Apple Added                 ------------
  66.  
  67.     SCSIGetVirtualIDInfo        = 0x80,        // Find out which bus old ID is on                            
  68.     SCSIGenerateInterleaveID    = 0x81,        // Generate a new interleave factor
  69.     SCSILoadDriver                = 0x82,        // Load a driver for a device ident.
  70.     SCSIOldCall                    = 0x84,        // XPT->SIM private call for old-API
  71.     SCSICreateRefNumXref        = 0x85,        // Register a DeviceIdent to drvr RefNum xref
  72.     SCSILookupRefNumXref        = 0x86,        // Get DeviceIdent to drvr RefNum xref
  73.     SCSIRemoveRefNumXref        = 0x87,        // Remove a DeviceIdent to drvr RefNum xref
  74.     SCSIRegisterWithNewXPT        = 0x88        // XPT has changed - SIM needs to re-register itself
  75.  
  76. //------------ 3rd-party Vendor Unique     ------------                            
  77.  
  78. // 0xC0 thru 0xFF
  79. };
  80.  
  81.  
  82. /********************************************************************/
  83. /*    SCSI Parameter Block Elements                                    */
  84. /********************************************************************/
  85.  
  86. typedef pascal void (*CallbackProc) (void * ioPtr);                    //            <SM6> pdw
  87.  
  88.  
  89. //————— Allocation length defines for some of the fields ————— <SM9>
  90.  
  91. #define        handshakeDataLength        8        // Handshake data length
  92. #define        maxCDBLength            16         // Space for the CDB bytes/pointer
  93. #define        vendorIDLength            16      // ASCII string len for Vendor ID 
  94.  
  95.  
  96. //————— Define DeviceIdent structure —————
  97.  
  98. typedef struct DeviceIdent 
  99. {
  100.     uchar        diReserved;            // reserved
  101.     uchar        bus;                // SCSI - Bus #
  102.     uchar        targetID;            // SCSI - Target SCSI ID
  103.     uchar        LUN;                // SCSI - LUN 
  104. } DeviceIdent;
  105.  
  106.  
  107. //————— Command Descriptor Block structure —————
  108.  
  109. typedef union CDB
  110. {
  111.     uchar *        cdbPtr;                        // ptr to the CDB bytes to send, or…
  112.     uchar        cdbBytes[ maxCDBLength ];    // actual CDB to send                    <SM6> pdw
  113. } CDB, *CDBPtr;
  114.  
  115.  
  116. //————— Scatter/gather list element —————
  117.  
  118. typedef    struct SGRecord 
  119. {
  120.     Ptr        SGAddr;
  121.     ulong    SGCount;
  122. } SGRecord;
  123.  
  124.  
  125.  
  126.  
  127. /********************************************************************/
  128. /*    SCSI Parameter Block Definitions                                */
  129. /********************************************************************/
  130.  
  131. //====== Common SCSI PB header fields macro ======
  132.  
  133. #define SCSIPBHdr \
  134.     struct SCSIHdr * qLink;                /* (internal) Q link to next PB         */ \
  135.     short            scsiReserved1;        /* ->     reserved for input                */ \
  136.     ushort            scsiPBLength;        /* -> Length of the entire PB            */ \
  137.     uchar            scsiFunctionCode;    /* -> function selector                 */ \
  138.     uchar            scsiReserved2;        /* <-     reserved for output                */ \
  139.     OSErr            scsiResult;            /* <- Returned result                     */ \
  140.     DeviceIdent        scsiDevice;            /* -> Device Identifier (bus+target+lun)*/ \
  141.     CallbackProc    scsiCompletion;        /* -> Callback on completion function      */ \
  142.     ulong            scsiFlags;            /* -> assorted flags                    */ \
  143.     uchar *            scsiDriverStorage;    /* <> Ptr for driver private use        */ \
  144.     Ptr                scsiXPTprivate;        /* private field for use in XPT            */ \
  145.     long            scsiReserved3;        /* reserved                                */
  146. // end of SCSIPBHdr
  147.  
  148.  
  149. //——————————————  SCSI PB Header  ——————————————
  150.  
  151. typedef struct SCSIHdr
  152. {
  153.     SCSIPBHdr
  154. } SCSIHdr;
  155.  
  156. typedef struct SCSI_PB
  157. {
  158.     SCSIPBHdr
  159. } SCSI_PB;
  160.  
  161.  
  162. //——————————————  SCSI I/O Request PB  ——————————————        <SM6> pdw from prev <SM6>
  163.                                                                 
  164. #define SCSI_IO_Macro \
  165.     SCSIPBHdr                            /* Header information fields                        */ \
  166.     ushort        scsiResultFlags;        /* <- Flags which modify the scsiResult field        */ \
  167.     ushort        scsiInterleaveID;        /* -> used to designate interleavability of request    */ \
  168.     uchar *        scsiDataPtr;            /* -> Pointer to the data buffer or the S/G list      */ \
  169.     ulong        scsiDataLength;            /* -> Data transfer length                            */ \
  170.     uchar *        scsiSensePtr;            /* -> Ptr to autosense data buffer                  */ \
  171.     uchar        scsiSenseLength;        /* -> size of the autosense buffer                     */ \
  172.     uchar        scsiCDBLength;            /* -> Number of bytes for the CDB                      */ \
  173.     ushort        scsiSGListCount;        /* -> num of scatter gather list entries              */ \
  174.     ulong        scsiReserved4;            /* <-     reserved for output                            */ \
  175.     uchar        scsiSCSIstatus;            /* <- Returned scsi device status                      */ \
  176.     char        scsiSenseResidual;        /* <- Autosense residual length                      */ \
  177.     ushort        scsiReserved5;            /* <-     reserved for output                             */ \
  178.     long        scsiDataResidual;        /* <- Returned Transfer residual length              */ \
  179.     CDB            scsiCDB;                /* -> Actual CDB or pointer to CDB                  */ \
  180.     long        scsiTimeout;            /* -> Timeout value (Time Mgr format) (CAM timeout) */ \
  181.     uchar *        scsiMessagePtr;            /* -> Pointer to the message buffer -target md only    */ \
  182.     ushort        scsiMessageLen;            /* -> Num of bytes in the msg bfr    -target md only    */ \
  183.     ushort        scsiIOFlags;            /* -> additional I/O flags                               */ \
  184.     uchar        scsiTagAction;            /* -> What to do for tag queuing                       */ \
  185.     uchar        scsiReserved6;            /* ->     reserved for input                             */ \
  186.     ushort        scsiReserved7;            /* ->     reserved for input                             */ \
  187.     ushort        scsiSelectTimeout;        /* -> Select timeout value                             */ \
  188.     uchar        scsiDataType;            /* -> Data description type (i.e. buffer, TIB, S/G)    */ \
  189.     uchar        scsiTransferType;        /* -> Transfer type (i.e. Blind vs Polled)             */ \
  190.     ulong        scsiReserved8;            /* ->     reserved for input                             */ \
  191.     ulong        scsiReserved9;            /* ->     reserved for input                             */ \
  192.     ushort        scsiHandshake[handshakeDataLength];    /* -> handshaking points (null term'd)    */ \
  193.     ulong        scsiReserved10;            /* ->     reserved for input                             */ \
  194.     ulong        scsiReserved11;            /* ->   reserved for input                            */ \
  195.     struct SCSI_IO *scsiCommandLink;    /* -> Ptr to the next PB in linked cmd chain         */ \
  196.                                         \
  197.     uchar        scsiSIMpublics[8];        /* ->     reserved for input to 3rd-party SIMs        */ \
  198.     uchar        scsiAppleReserved6[8];    /* ->    reserved for input                              */ \
  199.                                         \
  200. /* XPT layer privates (for old-API emulation) */ \
  201.                                         \
  202.     ushort        scsiCurrentPhase;        /* <- phase upon completing old call                  */ \
  203.     short        scsiSelector;            /* -> selector specified in old calls                  */ \
  204.     OSErr        scsiOldCallResult;        /* <- result of old call                              */ \
  205.     uchar        scsiSCSImessage;        /* <- Returned scsi device message (for SCSIComplete)*/ \
  206.     uchar        XPTprivateFlags;        /* <> various flags                                   */ \
  207.     uchar        XPTextras[12];            /*                                                    */
  208.  
  209. // end of SCSI_IO_Macro
  210.  
  211.  
  212. typedef struct SCSI_IO
  213. {
  214.     SCSI_IO_Macro
  215. } SCSI_IO;
  216. //                                                                <SM6> pdw from prev <SM6>
  217. #define SCSIExecIOPB    SCSI_IO
  218.     
  219.  
  220.     
  221.  
  222. //——————————————  Bus inquiry PB ——————————————
  223. typedef struct SCSIBusInquiryPB
  224. {
  225.     SCSIPBHdr                            // Header information fields
  226.     ushort        scsiEngineCount;        // <- Number of engines on HBA
  227.     ushort        scsiMaxTransferType;    // <- Number of transfer types for this HBA
  228.  
  229.     ulong        scsiDataTypes;            // <- which data types are supported by this SIM
  230.  
  231.     ushort        scsiIOpbSize;            // <- Size of SCSI_IO PB for this SIM/HBA        <SM6> pdw
  232.     ushort        scsiMaxIOpbSize;        // <- Size of max SCSI_IO PB for all SIM/HBAs    <SM6> pdw
  233.     
  234.     ulong        scsiFeatureFlags;        // <- Supported features flags field
  235.  
  236.     uchar        scsiVersionNumber;        // <- Version number for the SIM/HBA
  237.     uchar        scsiHBAInquiry;            // <- Mimic of INQ byte 7 for the HBA
  238.     uchar        scsiTargetModeFlags;    // <- Flags for target mode support
  239.     uchar        scsiScanFlags;            // <- Scan related feature flags
  240.  
  241.     ulong        scsiSIMPrivatesPtr;        // <- Ptr to SIM private data area
  242.     ulong        scsiSIMPrivatesSize;    // <- Size of SIM private data area
  243.     ulong        scsiAsyncFlags;            // <- Event cap. for Async Callback
  244.  
  245.     uchar        scsiHiBusID;            // <- Highest path ID in the subsystem 
  246.     uchar        scsiInitiatorID;        // <- ID of the HBA on the SCSI bus
  247.     ushort        scsiBIReserved0;
  248.  
  249.     ulong        scsiBIReserved1;        // <- 
  250.     ulong        scsiFlagsSupported;        // <- which scsiFlags are supported
  251.  
  252.     ushort        scsiIOFlagsSupported;    // <- which scsiIOFlags are supported
  253.     ushort         scsiWeirdStuff;            // <- 
  254.     ushort        scsiMaxTarget;            // <- maximum Target number supported
  255.     ushort        scsiMaxLUN;                // <- maximum Logical Unit number supported
  256.  
  257.     char        scsiSIMVendor[ vendorIDLength ];        // <- Vendor ID of SIM (or XPT if bus<FF)    <SM6> pdw
  258.     char        scsiHBAVendor[ vendorIDLength ];        // <- Vendor ID of the HBA                 <SM6> pdw
  259.     char        scsiControllerFamily[ vendorIDLength ];    // <- Family of SCSI Controller
  260.     char        scsiControllerType[ vendorIDLength ];    // <- Specific Model of SCSI Controller used
  261.  
  262.     char        scsiXPTversion[4];        // <- version number of XPT
  263.     char        scsiSIMversion[4];        // <- version number of SIM
  264.     char        scsiHBAversion[4];        // <- version number of HBA
  265.     
  266.     uchar        scsiHBAslotType;        // <- type of "slot" that this HBA is in
  267.     uchar        scsiHBAslotNumber;        // <- slot number of this HBA
  268.     ushort        scsiSIMsRsrcID;            // <- resource ID of this SIM
  269.     
  270.     ushort         scsiBIReserved3;        // <- 
  271.     ushort        scsiAdditionalLength;    // <- additional BusInquiry PB len
  272. } SCSIBusInquiryPB;
  273.  
  274.  
  275. //——————————————  Abort SIM Request PB  ——————————————
  276. typedef struct SCSIAbortCommandPB
  277. {
  278.     SCSIPBHdr                            // Header information fields
  279.     SCSI_IO *     scsiIOptr;                // Pointer to the PB to abort
  280. } SCSIAbortCommandPB;                    // <SM3>
  281.  
  282.  
  283. //——————————————  Terminate I/O Process Request PB  ——————————————
  284. typedef struct SCSITerminateIOPB
  285. {
  286.     SCSIPBHdr                            // Header information fields
  287.     SCSI_IO *     scsiIOptr;                // Pointer to the PB to terminate
  288. } SCSITerminateIOPB;                    // <SM3>
  289.  
  290.  
  291. //——————————————  Reset SCSI Bus PB ——————————————
  292. typedef struct SCSIResetBusPB
  293. {
  294.     SCSIPBHdr                            // Header information fields
  295. } SCSIResetBusPB;                        // <SM3>
  296.  
  297.  
  298. //——————————————  Reset SCSI Device PB  ——————————————
  299. typedef struct SCSIResetDevicePB
  300. {
  301.     SCSIPBHdr                            // Header information fields
  302. } SCSIResetDevicePB;                    // <SM3>
  303.  
  304.  
  305. //——————————————  Release SIM Queue PB  ——————————————
  306. typedef struct SCSIReleaseQPB
  307. {
  308.     SCSIPBHdr                            // Header information fields
  309. } SCSIReleaseQPB;
  310.  
  311.  
  312. //——————————————  Set Async Event Callback PB  ——————————————
  313. typedef struct SCSISetAsyncCallbackPB
  314. {
  315.     SCSIPBHdr                            // Header information fields
  316.     ulong        scsiEventFlags;            // -> events to be notified of
  317.     void        (*scsiEventCallback)();    // -> routine to call when event occurs
  318.     uchar *        scsiEventInfoPtr;        // -> ptr to buffer for additional info
  319.     uchar        scsiEventInfoLen;        // -> length of buffer
  320.     uchar        scsiReserved11;            // 
  321.     ushort        scsiReserved12;            // 
  322. } SCSISetAsyncCallbackPB;
  323.  
  324.  
  325. //——————————————  SCSI Get Virtual ID Info PB  ——————————————                                    <SM6> pdw
  326. typedef struct SCSIGetVirtualIDInfoPB
  327. {
  328.     SCSIPBHdr                        // Header information fields 
  329.     ushort        scsiOldCallID;        // -> SCSI ID of device in question
  330.     Boolean        scsiExists;            // <- true if device exists
  331. } SCSIGetVirtualIDInfoPB;
  332.  
  333.  
  334. //——————————————  SCSI Generate Interleave ID PB  ——————————————                                    <SM6> pdw
  335. typedef struct SCSIGenerateInterleaveIDPB
  336. {
  337.     SCSIPBHdr                        // Header information fields 
  338.     ushort        scsiInterleaveID;    // <- SCSI ID of device in question
  339.     ushort        scsiReserved13;        // 
  340. } SCSIGenerateInterleaveIDPB;
  341.  
  342.  
  343. //——————————————  Create/Lookup/Remove RefNum for Device PB  ——————————————
  344. typedef struct SCSI_Driver_PB
  345. {
  346.     SCSIPBHdr                            // Header information fields
  347.     short        scsiDriver;                // -> DriverRefNum, For SetDriver
  348.                                         // <- For GetNextDriver
  349.     ushort        scsiDriverFlags;        // <> Details of driver/device
  350.     DeviceIdent    scsiNextDevice;            // <- DeviceIdent of the NEXT Item in the list 
  351. } SCSI_Driver_PB;
  352.  
  353.  
  354. //——————————————  Load Driver PB ——————————————    <LW6> DCB
  355. typedef struct SCSILoadDriverPB
  356. {
  357.     SCSIPBHdr                            // Header information fields
  358.     short        scsiLoadedRefNum;        // <- SIM returns refnum of driver
  359.     Boolean        scsiDiskLoadFailed;        // -> if true, indicates call after failure to load
  360. } SCSILoadDriverPB;                        //
  361.  
  362. //======================================================================
  363.  
  364. /******************************************************************************/
  365. // Values for the fields in SCSI PBs
  366. /******************************************************************************/
  367.  
  368. //———————————————————————————————————————————————————————————————————————————————————
  369. // Defines for the scsiTransferType field
  370. //———————————————————————————————————————————————————————————————————————————————————
  371.  
  372. enum {
  373.         scsiTransferBlind = 0,
  374.         scsiTransferPolled
  375. };    
  376.  
  377. //———————————————————————————————————————————————————————————————————————————————————
  378. // Defines for the scsiDataType field
  379. //———————————————————————————————————————————————————————————————————————————————————
  380.  
  381. enum {
  382.         scsiDataBuffer     = 0,        // single contiguous buffer supplied 
  383.         scsiDataTIB     = 1,        // TIB supplied (ptr in scsiDataPtr)
  384.         scsiDataSG         = 2            // scatter/gather list supplied 
  385. };    
  386.  
  387. //———————————————————————————————————————————————————————————————————————————————————
  388. // Defines for the SCSIMgr scsiResult field in the PB header.
  389. //  $E100 thru  E1FF
  390. // -$1EFF thru -1E00
  391. // -#7935 thru -7681 
  392. //———————————————————————————————————————————————————————————————————————————————————
  393.  
  394. #define        scsiErrorBase        -7936                    // = 0xE100 
  395.  
  396. enum {                                                // <SM9> changed to enums
  397.     scsiRequestInProgress        = 1,                    // 1     = PB request is in progress
  398.  
  399. // Execution failed  00-2F
  400.     scsiRequestAborted            = (scsiErrorBase+0x02),    // -7934 = PB request aborted by the host
  401.     scsiUnableToAbort            = (scsiErrorBase+0x03),    // -7933 = Unable to Abort PB request
  402.     scsiNonZeroStatus            = (scsiErrorBase+0x04),    // -7932 = PB request completed with an err
  403.     scsiUnused05                = (scsiErrorBase+0x05),    // -7931 = 
  404.     scsiUnused06                = (scsiErrorBase+0x06),    // -7930 = 
  405.     scsiUnused07                = (scsiErrorBase+0x07),    // -7929 = 
  406.     scsiUnused08                = (scsiErrorBase+0x08),    // -7928 = 
  407.     scsiUnableToTerminate        = (scsiErrorBase+0x09),    // -7927 = Unable to Terminate I/O PB req
  408.     scsiSelectTimeout            = (scsiErrorBase+0x0A),    // -7926 = Target selection timeout
  409.     scsiCommandTimeout            = (scsiErrorBase+0x0B),    // -7925 = Command timeout 
  410.     scsiIdentifyMessageRejected    = (scsiErrorBase+0x0C),    // -7924 = 
  411.     scsiMessageRejectReceived    = (scsiErrorBase+0x0D),    // -7923 = Message reject received 
  412.     scsiSCSIBusReset            = (scsiErrorBase+0x0E),    // -7922 = SCSI bus reset sent/received
  413.     scsiParityError                = (scsiErrorBase+0x0F),    // -7921 = Uncorrectable parity error occured
  414.     scsiAutosenseFailed            = (scsiErrorBase+0x10),    // -7920 = Autosense: Request sense cmd fail
  415.     scsiUnused11                = (scsiErrorBase+0x11),    // -7919 = 
  416.     scsiDataRunError            = (scsiErrorBase+0x12),    // -7918 = Data overrun/underrun error 
  417.     scsiUnexpectedBusFree        = (scsiErrorBase+0x13),    // -7917 = Unexpected BUS free 
  418.     scsiSequenceFailed            = (scsiErrorBase+0x14),    // -7916 = Target bus phase sequence failure
  419.     scsiWrongDirection            = (scsiErrorBase+0x15),    // -7915 = Data phase was in unexpected direction
  420.     scsiUnused16                = (scsiErrorBase+0x16),    // -7914 = 
  421.     scsiBDRsent                    = (scsiErrorBase+0x17),    // -7913 = A SCSI BDR msg was sent to target
  422.     scsiTerminated                = (scsiErrorBase+0x18),    // -7912 = PB request terminated by the host
  423.     scsiNoNexus                    = (scsiErrorBase+0x19),    // -7911 = Nexus is not established
  424.     scsiCDBReceived                = (scsiErrorBase+0x1A),    // -7910 = The SCSI CDB has been received
  425.  
  426. // Couldn't begin execution  30-3F
  427.     scsiTooManyBuses            = (scsiErrorBase+0x30),    // -7888 = Register failed because we're full
  428.     scsiBusy                    = (scsiErrorBase+0x31),    // -7887 = SCSI subsystem is busy
  429.     scsiProvideFail                = (scsiErrorBase+0x32),    // -7886 = Unable to provide requ. capability
  430.     scsiDeviceNotThere            = (scsiErrorBase+0x33),    // -7885 = SCSI device not installed/there 
  431.     scsiNoHBA                    = (scsiErrorBase+0x34),    // -7884 = No HBA detected Error
  432.     scsiDeviceConflict            = (scsiErrorBase+0x35),    // -7883 = sorry, max 1 refNum per DeviceIdent
  433.     scsiNoSuchXref                = (scsiErrorBase+0x36),    // -7882 = no such RefNum xref
  434.     scsiQLinkInvalid            = (scsiErrorBase+0x37),    // -7881 = pre-linked PBs not supported    // <LW14> pdw Fß
  435.  
  436. // Parameter errors  40-7F
  437.     scsiPBLengthError            = (scsiErrorBase+0x40),    // -7872 = length (scsiPBLength) is insuf'ct/invalid
  438.     scsiFunctionNotAvailable    = (scsiErrorBase+0x41),    // -7871 = The requ. func is not available 
  439.     scsiRequestInvalid            = (scsiErrorBase+0x42),    // -7970 = PB request is invalid
  440.     scsiBusInvalid                = (scsiErrorBase+0x43),    // -7969 = Bus ID supplied is invalid 
  441.     scsiTIDInvalid                = (scsiErrorBase+0x44),    // -7868 = Target ID supplied is invalid
  442.     scsiLUNInvalid                = (scsiErrorBase+0x45),    // -7867 = LUN supplied is invalid 
  443.     scsiIIDInvalid                = (scsiErrorBase+0x46),    // -7866 = The initiator ID is invalid 
  444.     scsiDataTypeInvalid            = (scsiErrorBase+0x47),    // -7865 = scsiDataType requested is not supported
  445.     scsiTransferTypeInvalid        = (scsiErrorBase+0x48),    // -7864 = scsiTransferType field is too high
  446.     scsiCDBLengthInvalid        = (scsiErrorBase+0x49)    // -7863 = scsiCDBLength field is too big
  447. };
  448.  
  449. #define scsiExecutionErrors        scsiErrorBase
  450. #define scsiNotExecutedErrors    scsiTooManyBuses
  451. #define scsiParameterErrors        scsiPBLengthError
  452.  
  453. //———————————————————————————————————————————————————————————————————————————————————
  454. //  Defines for the scsiResultFlags field
  455. //———————————————————————————————————————————————————————————————————————————————————
  456.  
  457. #define    scsiSIMQFrozen            0x0001    // The SIM queue is frozen w/this err
  458. #define    scsiAutosenseValid        0x0002    // Autosense data valid for target 
  459. #define    scsiBusNotFree            0x0004    // At time of callback, SCSI bus is not free 
  460.  
  461.  
  462. //———————————————————————————————————————————————————————————————————————————————————
  463. // Defines for the scsiFlags field in the PB header for the SCSIExecIO function
  464. //———————————————————————————————————————————————————————————————————————————————————
  465.  
  466. enum
  467. {
  468. // 1st Byte
  469.  
  470.     scsibDisableAutosense        = 29,    // Disable auto sense feature
  471.     scsibFlagReservedA            = 28,    // 
  472.     
  473.     scsibFlagReserved0            = 27,    // 
  474.     scsibCDBLinked                = 26,    // The PB contains a linked CDB
  475.     scsibQEnable                = 25,    // Target queue actions are enabled
  476.     scsibCDBIsPointer            = 24,    // The CDB field contains a pointer
  477.     
  478. // 2nd Byte
  479.     
  480.     scsibFlagReserved1            = 23,    // 
  481.     scsibInitiateSyncData        = 22,    // Attempt Sync data xfer and SDTR
  482.     scsibDisableSyncData        = 21,    // Disable sync, go to async
  483.     scsibSIMQHead                = 20,    // Place PB at the head of SIM Q
  484.     
  485.     scsibSIMQFreeze                = 19,    // Return the SIM Q to frozen state
  486.     scsibSIMQNoFreeze            = 18,    // Disallow SIM Q freezing
  487.     scsibDoDisconnect            = 17,    // Definitely do disconnect
  488.     scsibDontDisconnect            = 16,    // Definitely don't disconnect
  489.     
  490. // 3rd Byte
  491.     
  492.     scsibFlagReserved3            = 15,    // 
  493.     scsibDataDMAready            = 14,    // Data buffer(s) are ready for DMA
  494.     scsibDataPhysical            = 13,    // SG/Buffer data ptrs are physical
  495.     scsibSensePhysical            = 12,    // Autosense buffer ptr is physical
  496.     
  497.     scsibFlagReserved5            = 11,    // 
  498.     scsibFlagReserved6            = 10,    // 
  499.     scsibFlagReserved7            = 9,    // 
  500.     scsibFlagReserved8            = 8,    // 
  501.     
  502. // 4th Byte - Target Mode Flags
  503.     
  504.     scsibDataBufferValid        = 7,    // Data buffer valid
  505.     scsibStatusBufferValid        = 6,    // Status buffer valid 
  506.     scsibMessageBufferValid        = 5,    // Message buffer valid
  507.     scsibFlagReserved9            = 4,    // 
  508.     
  509.     scsibTargetPhaseMode        = 3,    // The SIM will run in phase mode
  510.     scsibTargetPBAvail            = 2,    // Target PB available 
  511.     scsibDisableAutoDisconnect    = 1,    // Disable autodisconnect
  512.     scsibDisableAutoSaveRestore    = 0        // Disable autosave/restore ptrs
  513. };
  514.  
  515.  
  516. // 1st Byte
  517.  
  518. #define    scsiDirectionMask        0xC0000000    // Data direction mask
  519.  
  520. #define scsiDirectionNone        0xC0000000    // Data direction (11: no data)
  521. #define    scsiDirectionReserved    0x00000000    // Data direction (00: reserved)
  522. #define    scsiDirectionOut        0x80000000    // Data direction (10: DATA OUT)
  523. #define    scsiDirectionIn            0x40000000    // Data direction (01: DATA IN)
  524. #define    scsiDisableAutosense    0x20000000    // Disable auto sense feature
  525. #define    scsiFlagReservedA        0x10000000    // 
  526.  
  527. #define    scsiFlagReserved0        0x08000000    // 
  528. #define    scsiCDBLinked            0x04000000    // The PB contains a linked CDB
  529. #define    scsiQEnable                0x02000000    // Target queue actions are enabled
  530. #define    scsiCDBIsPointer        0x01000000    // The CDB field contains a pointer
  531.  
  532. // 2nd Byte
  533.  
  534. #define    scsiFlagReserved1        0x00800000    // 
  535. #define    scsiInitiateSyncData    0x00400000    // Attempt Sync data xfer and SDTR
  536. #define    scsiDisableSyncData        0x00200000    // Disable sync, go to async
  537. #define    scsiSIMQHead            0x00100000    // Place PB at the head of SIM Q
  538.  
  539. #define    scsiSIMQFreeze            0x00080000    // Return the SIM Q to frozen state
  540. #define    scsiSIMQNoFreeze        0x00040000    // Disallow SIM Q freezing
  541. #define    scsiDoDisconnect        0x00020000    // Definitely do disconnect
  542. #define    scsiDontDisconnect        0x00010000    // Definitely don't disconnect
  543.  
  544. // 3rd Byte
  545.  
  546. #define    scsiFlagReserved3        0x00008000    // 
  547. #define    scsiDataDMAready        0x00004000    // Data buffer(s) are ready for DMA
  548. #define    scsiDataPhysical        0x00002000    // SG/Buffer data ptrs are physical
  549. #define    scsiSensePhysical        0x00001000    // Autosense buffer ptr is physical
  550.  
  551. #define    scsiFlagReserved5        0x00000800    // 
  552. #define    scsiFlagReserved6        0x00000400    // 
  553. #define    scsiFlagReserved7        0x00000200    // 
  554. #define    scsiFlagReserved8        0x00000100    // 
  555.  
  556. // 4th Byte - Target Mode Flags
  557.  
  558. #define    scsiDataBufferValid            0x00000080    // Data buffer valid
  559. #define    scsiStatusBufferValid        0x00000040    // Status buffer valid 
  560. #define    scsiMessageBufferValid        0x00000020    // Message buffer valid
  561. #define    scsiFlagReserved9            0x00000010    // 
  562.  
  563. #define    scsiTargetPhaseMode            0x00000008    // The SIM will run in phase mode
  564. #define    scsiTargetPBAvail            0x00000004    // Target PB available 
  565. #define    scsiDisableAutoDisconnect    0x00000002    // Disable autodisconnect
  566. #define    scsiDisableAutoSaveRestore    0x00000001    // Disable autosave/restore ptrs
  567.  
  568. #define    scsiTargetModeFlagsMask        0x000000FF    // all of the target mode bits
  569.  
  570.  
  571.  
  572. //————————————————————————————————————————
  573. // scsiIOFlags
  574. //————————————————————————————————————————
  575.  
  576. #define    scsiNoParityCheck            0x0002    // disable parity checking 
  577. #define    scsiDisableSelectWAtn        0x0004    // disable select w/Atn 
  578. #define    scsiSavePtrOnDisconnect        0x0008    // do SaveDataPointer upon Disconnect msg
  579. #define    scsiNoBucketIn                0x0010    // don’t bit bucket in during this I/O
  580. #define    scsiNoBucketOut                0x0020    // don’t bit bucket out during this I/O
  581. #define    scsiDisableWide                0x0040    // disable wide transfer negotiation
  582. #define    scsiInitiateWide            0x0080    // initiate wide transfer negotiation
  583. #define    scsiRenegotiateSense        0x0100    // renegotiate sync/wide before issuing autosense
  584.  
  585. #define    scsiIOFlagReserved0080        0x0080    // 
  586. #define    scsiIOFlagReserved8000        0x8000    // 
  587.  
  588.  
  589. //——————————————————————————————————————————————————————————————————————
  590. // Defines for the SIM/HBA queue actions.  These values are used in the
  591. // SCSIExecIOPB, for the queue action field. [These values should match the
  592. // defines from some other include file for the SCSI message phases.  We may
  593. // not need these definitions here. ]
  594.  
  595. enum {
  596.     scsiSimpleQTag            = 0x20,        // Tag for a simple queue
  597.     scsiHeadQTag            = 0x21,        // Tag for head of queue 
  598.     scsiOrderedQTag            = 0x22         // Tag for ordered queue 
  599. };
  600.  
  601. //——————————————————————————————————————————————————————————————————————
  602. // Defines for the Bus Inquiry PB fields.
  603. //——————————————————————————————————————————————————————————————————————
  604.  
  605. // scsiHBAInquiry field bits
  606.  
  607. #define    scsiBusMDP                0x80    // Supports Modify Data Pointer message
  608. #define    scsiBusWide32            0x40    // Supports 32 bit wide SCSI
  609. #define    scsiBusWide16            0x20    // Supports 16 bit wide SCSI
  610. #define    scsiBusSDTR                0x10    // Supports Sync Data Transfer Req message
  611. #define    scsiBusLinkedCDB        0x08    // Supports linked CDBs
  612. #define    scsiBusTagQ                0x02    // Supports tag queue message 
  613. #define    scsiBusSoftReset        0x01    // Supports soft reset
  614.  
  615.  
  616. // scsiDataTypes field bits 
  617. //    bits 0->15 Apple-defined, 16->30 3rd-party unique, 31 = reserved
  618.  
  619. #define scsiBusDataTIB            (1<<scsiDataTIB)        // TIB supplied (ptr in scsiDataPtr)
  620. #define scsiBusDataBuffer        (1<<scsiDataBuffer)    // single contiguous buffer supplied 
  621. #define scsiBusDataSG            (1<<scsiDataSG)        // scatter/gather list supplied 
  622.  
  623. #define scsiBusDataReserved        0x80000000    //  
  624.  
  625.  
  626. // scsiTargetModeFlags field bits
  627.  
  628. #define scsiBusTargetMdProcessor    0x80    // Target mode processor mode 
  629. #define scsiBusTargetMdPhase        0x40    // Target mode phase cog. mode
  630.  
  631.  
  632. // scsiScanFlags field bits
  633.  
  634. #define scsiBusScansDevices            0x80    // Bus scans for and maintains device list
  635. #define scsiBusScansOnInit            0x40    // Bus scans performed at power-up/reboot
  636. #define scsiBusLoadsROMDrivers        0x20    // may load ROM drivers to support targets
  637.  
  638.  
  639. // scsiFeatureFlags field bits
  640.  
  641. #define scsiBusInternalExternalMask        0x000000C0    // bus internal/external mask
  642. #define scsiBusInternalExternalUnknown    0x00000000    // not known whether bus is inside or outside
  643. #define scsiBusInternalExternal            0x000000C0    // bus goes inside and outside the box
  644. #define scsiBusInternal                    0x00000080    // bus goes inside the box
  645. #define scsiBusExternal                    0x00000040    // bus goes outside the box
  646.  
  647. #define scsiBusCacheCoherentDMA            0x00000020    // DMA is cache coherent
  648. #define scsiBusOldCallCapable            0x00000010    // SIM is old call capable
  649.  
  650. #define scsiBusDifferential                0x00000004    // Single Ended (0) or Differential (1)
  651. #define scsiBusFastSCSI                    0x00000002    // HBA supports fast SCSI
  652. #define scsiBusDMAavailable                0x00000001    // DMA is available
  653.  
  654.  
  655. // scsiWeirdStuff field bits
  656.  
  657. #define scsiOddDisconnectUnsafeRead1    0x0001    // 
  658. #define scsiOddDisconnectUnsafeWrite1    0x0002    // 
  659. #define scsiTargetDrivenSDTRSafe        0x0010    // 
  660.  
  661.  
  662.  
  663. //———————————————————————————————————————————————————————————————————————————————————
  664. //  Defines for the scsiDriverFlags field (in SCSI_Driver_PB)
  665. //———————————————————————————————————————————————————————————————————————————————————
  666.  
  667. #define    scsiDeviceSensitive            0x0001    // Only driver should access this device
  668. #define    scsiDeviceNoOldCallAccess    0x0002    // no old call access to this device
  669.  
  670.  
  671.  
  672. //——————————————————————————————————————————————————————————————————————
  673. //  SIMinitInfo
  674. //——————————————————————————————————————————————————————————————————————
  675.  
  676. typedef struct {            // directions are for SCSIRegisterBus call ( -> parm, <- result)
  677.     uchar *        SIMstaticPtr;        // <- alloc. ptr to the SIM's static vars
  678.     long        staticSize;            // -> num bytes SIM needs for static vars
  679.     OSErr        (*SIMinit)();        // -> pointer to the SIM init routine
  680.     void        (*SIMaction)();        // -> pointer to the SIM action routine
  681.     long        (*SIM_ISR)();        // -> pointer to the SIM ISR routine
  682.     long        (*SIMInterruptPoll)();    // -> pointer to the SIM interrupt poll routine
  683.     void        (*NewOldCall)();    // -> pointer to the SIM NewOldCall routine
  684.     ushort        ioPBSize;            // -> size of SCSI_IO_PBs required for this SIM        <SM6> pdw
  685.     Boolean        oldCallCapable;        // -> true if this SIM can handle old-API calls
  686.     uchar        simInfoUnused1;        // ->
  687.     long        simInternalUse;        // xx not affected or viewed by XPT
  688.     void        (*XPT_ISR)();        // <- ptr to the XPT ISR
  689.     void        (*EnteringSIM)();    // <- ptr to the EnteringSIM routine
  690.     void        (*ExitingSIM)();    // <- ptr to the ExitingSIM routine
  691.     void        (*MakeCallback)();    // <- pointer to the XPT layer’s MakeCallback routine
  692.     ushort        busID;                // <- bus number for the registered bus
  693.     ushort        simInfoUnused3;        // <- 
  694.     long        simInfoUnused4;        // <- 
  695. } SIMinitInfo; 
  696.  
  697.  
  698.  
  699. /********* Glue between SCSI calls and SCSITrap format ***********/
  700.  
  701. enum {
  702.     xptSCSIAction            = 0x0001,
  703.     xptSCSIRegisterBus        = 0x0002,
  704.     xptSCSIDeregisterBus    = 0x0003,
  705.     xptSCSIReregisterBus    = 0x0004,
  706.     xptSCSIKillXPT            = 0x0005    // kills Mini-XPT after transition 
  707. };
  708.  
  709. #ifdef __cplusplus
  710. extern "C" {
  711. #endif
  712.  
  713. #pragma parameter __D0    SCSIAction(__A0)            /* moveq #kSCSIx, D0;  _SCSIAtomic */
  714. OSErr                    SCSIAction(SCSI_PB *)            = {0x7001, _SCSIAtomic}; 
  715.  
  716. #pragma parameter __D0    SCSIRegisterBus(__A0)
  717. OSErr                    SCSIRegisterBus(SIMinitInfo *)    = {0x7002, _SCSIAtomic}; 
  718.  
  719. #pragma parameter __D0    SCSIDeregisterBus(__A0)
  720. OSErr                    SCSIDeregisterBus(SIMinitInfo *)    = {0x7003, _SCSIAtomic}; 
  721.  
  722. #pragma parameter __D0    SCSIReRegisterBus(__A0)
  723. OSErr                    SCSIReRegisterBus(SIMinitInfo *)    = {0x7004, _SCSIAtomic}; 
  724.  
  725. #pragma parameter __D0    SCSIKillXPT(__A0)
  726. OSErr                    SCSIKillXPT(SIMinitInfo *)    = {0x7005, _SCSIAtomic}; 
  727.  
  728. #ifdef __cplusplus
  729. }
  730. #endif
  731.  
  732.  
  733.  
  734. #endif    // __ACAM__
  735.